package cn.caojun.basic.service.impl;

import cn.caojun.auth.domain.Role;
import cn.caojun.auth.query.RoleQuery;
import cn.caojun.basic.mapper.BaseMapper;
import cn.caojun.basic.query.BaseQuery;
import cn.caojun.basic.service.IBaseService;
import cn.caojun.basic.utils.PageList;
import cn.caojun.org.domain.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    BaseMapper<T> baseMapper;

    @Override
    @Transactional
    public void add(T t) {
        baseMapper.insert(t);
    }


    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }


    @Override
    @Transactional
    public void removeById(Serializable id) {
        baseMapper.deleteById(id);
    }

    @Override
    public T getById(Serializable id) {
        return baseMapper.loadById(id);
    }


    @Override
    public List<T> getAll() {
        return baseMapper.loadAll();
    }

    @Override
    public PageList<T> getLimteList(BaseQuery baseQuery) {
        Long size=baseMapper.getSize(baseQuery);
        if (size>0){
            List<T> roleList=baseMapper.getDate(baseQuery);
            return new PageList<>(size,roleList);
        }
        return new PageList<>();
    }


    @Override
    @Transactional
    public void batchRemove(List<Long> ids) {
        if (ids==null||ids.size()==0){
            throw new RuntimeException("");
        }else {
            baseMapper.batchDelete(ids);
        }
    }
}
